home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Snippets / Printing / SetPDiMC / SetPDiMC.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  3.6 KB  |  107 lines  |  [TEXT/MPS ]

  1. {[n+,u+,r+,d+,#+,j=13-/40/1o,t=2,o=95] PasMat formatting options}
  2.  
  3. {------------------------------------------------------------------------------
  4.  
  5. FILE SetPDiMC.p
  6.  Copyright Zz 1990
  7.  All rights revoked.
  8.  
  9. NAME
  10.  SetPDiMC -- An MPW tool to set the 'Printer Driver is MultiFinder Compatible' flag.
  11.  
  12. SYNOPSIS
  13.  SetPDiMC <filename>
  14.  
  15. DESCRIPTION
  16.  "SetPDiMC" automates the process of creating a printer driver.  The last step in
  17.  the process is usually to set the 'Printer Driver is MultiFinder Compatible' flag
  18.  that tells MultiFinder special things about handling the resources (see Learning
  19.  To Drive for more information about the PDiMC flag).  This tool can be called from
  20.  a makefile, and will simply set the PDiMC flag.
  21.  
  22. ------------------------------------------------------------------------------}
  23. {$R-}                                                                  { Turn off range checking}
  24. PROGRAM AbbreviateFName;
  25.  
  26.     USES                                                                 { $Load macstuff}
  27.         Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, { Standard Includes}
  28.         { $Load mpwstuff}
  29.         CursorCtl,                                                 { for the spinning cursor}
  30.         Signal,                                                      { to handle command-period}
  31.         PasLibIntf,                                              { for standard I/O, etc.}
  32.         IntEnv;                                                      { for argV and argC}
  33.  
  34.  
  35. {$S Main}
  36.  {*--------------------------------------*
  37.  | DoIt -- check resources in each file |
  38.  *--------------------------------------*}
  39.  
  40.     PROCEDURE DoIt;                                          { the guts of our program--in a procedure so the
  41.                                                                                 compiler can do register optimizations}
  42.         VAR
  43.             argVIndex:        INTEGER;
  44.             strIndex:            INTEGER;
  45.             arg:                    Str255;
  46.             fileName:            Str255;
  47.             theError:            INTEGER;
  48.             theFile:            INTEGER;
  49.             theAttrs:            INTEGER;
  50.             tester:                Handle;
  51.  
  52.         BEGIN                                                          {DoIt}
  53.             argVIndex := 1;
  54.             WHILE argVIndex < ArgC DO BEGIN {ArgC is the number of args plus one}
  55.                 arg := ArgV^[argVIndex]^;
  56.                 IF (LENGTH(arg) <> 0) THEN BEGIN
  57.                     IF arg[1] = '-' THEN BEGIN    { we have an option }
  58.                         { No options yet... }
  59.                     END ELSE BEGIN                            { it must be the font name}
  60.                             fileName := arg;
  61.                     END;
  62.                 END;
  63.                 argVIndex := argVIndex + 1;
  64.             END;
  65.  
  66.             (* Begin by opening the file.  You need to do this to call GetResFileAttrs. *)
  67.             theFile := OpenResFile(fileName);
  68.             theError := ResError;
  69.             IF theError <> noErr THEN
  70.                 WRITELN(Diagnostic, 'Error opening: ', theError)
  71.             ELSE BEGIN
  72.                 (* Point to the file we just opened. *)
  73.                 UseResFile(theFile);
  74.                 
  75.                 (* Load a resource we know will be there.  PDEF 4 is used to handle the     *)
  76.                 (* Printing Manager dialogs, so there should be one.                                            *)
  77.                 tester := GetResource('PDEF', 4);
  78.                 
  79.                 (* Now get the current resource file attributes.    *)
  80.                 theAttrs := GetResFileAttrs(theFile);
  81.  
  82.                 (* Set the flag that we're interested in.  The lowest bit. *)
  83.                 theAttrs := BitOr(theAttrs, 1);
  84.                 
  85.                 (* Now set the attributes and check for errors. *)
  86.                 SetResFileAttrs(theFile, theAttrs);
  87.                 theError := ResError;
  88.                 IF (theError <> noErr) THEN
  89.                     WRITELN(Diagnostic, 'Error setting attributes: ', theError);
  90.                 
  91.                 (* Now we need to mark at least one resource as being changed so that the            *)
  92.                 (* Resource Manager will write out the resource map of this file, thus                 *)
  93.                 (* setting the attributes.  If this is not done, the call to SetResFileAttrs    *)
  94.                 (* will be ignored.                                                                                                                        *)
  95.                 ChangedResource(tester);
  96.             END;
  97.             (* Finally close the file... *)
  98.             CloseResFile(theFile);
  99.         END;                                                             {DoIt}
  100.  
  101.  {*----------------------------*
  102.  | Abbreviate -- main program  |
  103.  *----------------------------*}
  104.     BEGIN                                                              {Abbreviate}
  105.         DoIt;                                                          { and call our routine}
  106.     END.                                                                 {Abbreviate}
  107.